package com.example.demo.controler;

import com.example.demo.entity.UserEntity;
import com.example.demo.service.UserService;
import com.example.demo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;
    @GetMapping("/hello")
    public String sayHello(){
        return "Hello World!";
    }

    @PostMapping("/login")
    public R doLogin(@RequestBody UserEntity user){
        UserEntity userEntity = userService.getByUserNameAndPassword(user);
        if (userEntity!=null){
            return  R.ok();
        }else {
            return R.error(88,"用户或密码错误");
        }
    }
    @PostMapping("/register")
    public R doRegister(@RequestBody UserEntity user){

        Integer integer = userService.userRegister(user);
        if (integer==1){
            return  R.ok();
        }else {
            return R.error(88,"失败");
        }
    }





}
